var datagridEvent;
var datagridDtl;
var dialogEvent;
var dialogEventDtl;
var dialogDtl;
var dialogEventPreview;
var dialogChart;
var chartDom;
var myChart;
$(function () {
    datagridEvent = $("#list").datagrid({
        method: "post",
        url: getRootPath() + "/exception/getEventList",
        fit: true,
        border: true,
        pageNumber: 1,
        pageSize: 20,
        pageList: [10, 20, 30, 50, 100],
        columns: [[
            {field:'ck',checkbox:true},
            {field: "eid", title: "EID", width: 30},
            {field: "wide_type", title: "广泛类", width: 120,
                formatter:function (value,row,index) {
                    if (value===0)
                    {return "订单资料异常";}
                    else if(value === 1)
                    {return "机型履历异常";}
                    else
                    {return "未知广泛类";}
                }
            },
            {field: "erp", title: "ERP编号", width: 140},
            {field: "machineType", title: "机型", width: 140},
            {field: "conDept", title: "事业部", width: 140},
            {field: "conBillNo", title: "订单号", width: 140},
            {field: "cusSentToName", title: "发往地", width: 120},
            {field: "pro_type", title: "产品类型", width: 60},
            {field: "problem_description", title: "问题描述", width: 160,
                formatter: function (value) {
                if (value!=null)
                { return "<span title='" + value + "'>" + value + "</span>";}
                else
                {return "";}
                }
            },
            {field: "analysis_result", title: "工程分析", width: 160,
                formatter: function (value) {
                    if (value!=null)
                    { return "<span title='" + value + "'>" + value + "</span>";}
                    else
                    {return "";}
                }
            },
            {field: "exp_proce_results", title: "工程建议长期方案", width: 160,
                formatter: function (value) {
                    if (value!=null)
                    { return "<span title='" + value + "'>" + value + "</span>";}
                    else
                    {return "";}
                }
            },
            {field: "exception_type_name", title: "问题属性", width: 120},
            {field: "dept_name", title: "责任部门", width: 60},
            {field: "temp_disposal", title: "临时方案", width: 160,
                formatter: function (value) {
                    if (value!=null)
                    { return "<span title='" + value + "'>" + value + "</span>";}
                    else
                    {return "";}
                }
            },
            {field: "subm_men", title: "提报人", width: 60},
            {field: "follow_up_people", title: "跟进人", width: 60},
            {field: "occurrence_time", title: "发生时间", width: 80},
            {field: "subm_time", title: "提报时间", width: 80},
            {field: "finish_time", title: "完成时间", width: 80},
            {field: "state", title: "状态", width: 50,
                formatter:function(value,row,index) {
                   if (value==0)
                   {return '<div style="color: red">等待处理</div>';}
                   else if(value==1)
                   {return '<div style="color: #f8e40a">正在处理</div>';}
                   else if(value==2)
                   {return '<div style="color: #1d9c30">处理完成</div>';}
                }
            },
            {field:"operation",title:"操作",width:250,
                formatter:function(value,row,index){
                var elementNode ="<span>";
                var btn = "<button style=\"\" onclick=\"queryDetails("+row.eid+")\" class=\"button-edit button-green\">异常处理细则</button>";
                var btn2 = "<button style=\"margin-left: 5px;\" onclick=\"edit("+index+")\" class=\"button-edit button-yellow\">修改</button>";
                var btn3 = "<button style=\"margin-left: 5px;\" onclick=\"remove("+row.eid+")\" class=\"button-edit button-red\">撤销</button>";
                if (row.state==2)
                {
                    elementNode=elementNode+btn+"</span>";
                    return elementNode;
                }
                else
                {
                    elementNode=elementNode+btn+btn2+btn3+"</span>";
                    return elementNode;
                }
            }
            },
        ]],
        groupField:"machineType",
        view:groupview,
        groupFormatter:function(value, rows){
            return value + ' - ' +'本页共'+ rows.length + ' 项异常';
        },
        onLoadSuccess: function (data) {
            $('.button-delete').linkbutton({});
            $('.button-edit').linkbutton({});
        },
        onDblClickRow: function (index, row) {
            event_preview(row);
        },
        pagination: true,
        striped: true,
        singleSelect:true,
        //工具条
        toolbar: "#toolbar",
    });
    //初始化select
    $.getJSON(getRootPath() + "/exception/list_exception_type", function (json) {
        $('#exception_type_id2').combobox({
            data: json.data, //获取到的json 数据
            valueField: "id",
            textField: "exception_type_name"
        });
    });

    $.getJSON(getRootPath() + "/exception/list_dept", function (json) {
        $('#dept_id').combobox({
            data: json.data, //获取到的json 数据
            valueField: "id",
            textField: "dept_name"
        });
    });

    $("#wide_type").combobox('setValue', '');
    $("#state").combobox('setValue', '');
    IniDetails();

    $("#form_wide_type").combobox({
        onChange:function (n,o)
        {
            if (n==0)
            {
                $("#analysis_result").textbox('disable');
                $("#exp_proce_results").textbox('disable');
                $("#analysis_result").textbox('setValue','');
                $("#exp_proce_results").textbox('setValue','');
            }
            else if (n==1)
            {
                $("#analysis_result").textbox('enable');
                $("#exp_proce_results").textbox('enable');
            }
        }
    });

    open_chart_dlg();
});

// 记录查询
function queryRecord() {
    $("#list").datagrid('load', {
        erp:$("#erp").val(),
        machineType:$("#machineType").val(),
        conDept:$("#conDept").val(),
        cusSentToName:$("#cusSentToName").val(),
        conBillNo:$("#conBillNo").val(),
        dept_id:$("#dept_id").combobox('getValue'),
        exception_type_id:$("#exception_type_id2").combobox('getValue'),
        subm_men:$("#subm_men").val(),
        follow_up_people:$("#follow_up_people").val(),
        wide_type:$("#wide_type").val(),
        state:$("#state").val(),
        occurrence_time_start:$("#occurrence_time_start").val(),
        occurrence_time_end:$("#occurrence_time_end").val(),
        submit_time_start:$("#submit_time_start").val(),
        submit_time_end:$("#submit_time_end").val()
        }
    );
}
function IniDetails() {

    datagridDtl = $("#details_list").datagrid({
        method: "get",
        url: getRootPath() + "/exception/getExceptionDtlList",
        fit: true,
        border: true,
        pageNumber: 1,
        pageSize: 20,
        pageList: [10, 20, 30, 50, 100],
        columns: [[
            {field:'ck',checkbox:true},
            {field: "eid", title: "eid", width: 30,hidden:true},
            {field: "dept_name", title: "处理部门", width: 140},
            {field: "content", title: "处理内容", width: 140},
            {field: "creat_time", title: "处理时间", width: 140},
            {field:"operation",title:"操作",width:220,
                formatter:function(value,row,index){
                    var elementNode ="<span>";
                    var btn = "<button style=\"margin-left: 5px;\" onclick=\"editDtl("+index+")\" class=\"button-edit button-yellow\">修改</button>";
                    var btn1 = "<button style=\"margin-left: 5px;\" onclick=\"removeDtl("+row.id+")\" class=\"button-edit button-red\">删除</button>";
                    elementNode=elementNode+btn+btn1+"</span>";
                    return elementNode;
                }
            },
        ]],
        onLoadSuccess: function (data) {
            $('.button-delete').linkbutton({});
            $('.button-edit').linkbutton({});
        },
        pagination: true,
        striped: true,
        singleSelect:true,
        //工具条
        toolbar: "#details_list_toolbar",
    });
}

function queryDetails(eid) {
    if (eid!=null)
    {
        $("#dlg_event_id").val(eid);
        console.info("queryDetails:eid="+$("#dlg_event_id").val());
        dialogEventDtl = $("#dlg_details").dialog({
            title: '异常处理细则',
            width: 800,
            height: 480,
            maximizable: false,
            modal: true,
            buttons: [{
                text: '确认',
                iconCls: 'icon-ok',
                handler: function () {
                    dialogEventDtl.dialog('close');
                }
            }, {
                text: '取消',
                handler: function () {
                    dialogEventDtl.dialog('close');
                }
            }]
        });
    }
    console.info("load:"+$("#dlg_event_id").val());
    $("#details_list").datagrid('load', {
            eid:$("#dlg_event_id").val()
        });
}

function remove(id) {
    if (id == null) {
        var row = datagridEvent.datagrid('getSelected');
        if (row == null) {
            U.msg('请先选择异常事件');
            return;
        } else {
            id = row.eid;
        }
    }

    parent.$.messager.confirm('提示', '撤销后该异常的处理细则将会删除且无法恢复您确定要撤销？', function (data) {
        if (data) {
            U.get({
                url: getRootPath() + '/exception/deleEvent?eid=' + id,
                loading: true,
                success: function (data) {
                    if (data.code == 200) {
                        U.msg('撤销成功');
                        queryRecord();
                    } else if (data.code == 400) {//参数验证失败
                        U.msg('参数验证失败');
                    } else if (data.code == 403) {
                        U.msg(data.message);
                    }
                    else {
                        U.msg('服务器异常');
                    }
                }
            });
        }
    });
}

function add() {

    dialogEvent = $("#dlg_event").dialog({
        title: '添加异常事件',
        width: 520,
        height: 480,
        maximizable: false,
        modal: true,
        buttons: [{
            text: '确认',
            iconCls: 'icon-ok',
            handler: function () {
                var isValid = $("#form_event").form('validate');

                var addObj = [];
                if (isValid) {
                    U.post({
                        url: getRootPath() + "/exception/addEvent",
                        loading: true,
                        data: getFormJson("#form_event", "", addObj),//$('#form_main').serialize(),
                        success: function (data) {
                            if (data.code == 200) {
                                U.msg('添加成功');
                                dialogEvent.dialog('close');
                                queryRecord();
                            } else if (data.code == 400) {
                                U.msg('参数验证失败');
                            } else if (data.code == 409) {
                                U.msg('已存在');
                            } else {
                                U.msg('服务器异常');
                            }
                        }
                    });
                }
            }
        }, {
            text: '取消',
            handler: function () {
                dialogEvent.dialog('close');
            }
        }]
    });
    $("#form_event").form("clear");
    $.getJSON(getRootPath() + "/exception/list_exception_type", function (json) {
        $('#exception_type_id').combobox({
            data: json.data, //获取到的json 数据
            valueField: "id",
            textField: "exception_type_name"
        });
    });

    $.getJSON(getRootPath() + "/exception/list_dept", function (json) {
        $('#resp_dept').combobox({
            data: json.data, //获取到的json 数据
            valueField: "id",
            textField: "dept_name"
        });
    });
    setVal("#form_subm_men", username);
}

function edit(id) {

    var row;
    if (id == null) {//点击datagrid上面的修改
        row = datagridEvent.datagrid('getSelected');
    } else {//点击datagrid对应行上的修改
        datagridEvent.datagrid('selectRow', id);
        row = datagridEvent.datagrid('getSelected');
    }

    if (row == null) {
        U.msg('请先选择一项异常事件');
        return;
    }

    /*
    $.getJSON(getRootPath() + "/mtManage/assets/list_dept", function (json) {
        $('#deptInfo').combobox({
            data: json.data, //获取到的json 数据
            valueField: "dept_id",
            textField: "dept_name"
        });
        console.log(row.deptId);
        $("#deptInfo").combobox('setValue', row.deptId);
    });
    */

    dialogEvent = $("#dlg_event").dialog({
        title: '编辑异常事件',
        width: 520,
        height: 480,
        maximizable: false,
        modal: true,
        buttons: [{
            text: '确认',
            iconCls: 'icon-ok',
            handler: function () {
                var isValid = $("#form_event").form('validate');
                var addObj = [{"name":"eid","value":row.eid}];
                if (isValid) {
                    U.post({
                        url: getRootPath() + "/exception/editEvent",
                        loading: true,
                        data: getFormJson("#form_event", "", addObj),
                        success: function (data) {
                            if (data.code == 200) {
                                U.msg('修改成功');
                                dialogEvent.dialog('close');
                                queryRecord();
                            }else if (data.code == 400) {//参数验证失败
                                U.msg('参数验证失败');
                            }else if (data.code == 403) {
                                U.msg(data.message);
                            }else if (data.code == 404) {
                                U.msg('未找到该分类');
                            } else if (data.code == 409) {
                                U.msg('该分类已存在');
                            } else {
                                U.msg('服务器异常');
                            }
                        }
                    });
                }
            }
        }, {
            text: '取消',
            handler: function () {
                dialogEvent.dialog('close');
            }
        }]
    });

    $.getJSON(getRootPath() + "/exception/list_exception_type", function (json) {
        $('#exception_type_id').combobox({
            data: json.data, //获取到的json 数据
            valueField: "id",
            textField: "exception_type_name"
        });
        console.log(row.exception_type_id);
        $("#exception_type_id").combobox('setValue', row.exception_type_id);
    });

    $.getJSON(getRootPath() + "/exception/list_dept", function (json) {
        $('#resp_dept').combobox({
            data: json.data, //获取到的json 数据
            valueField: "id",
            textField: "dept_name"
        });
        console.log(row.resp_dept);
        $("#resp_dept").combobox('setValue', row.resp_dept);
    });

    $("#form_wide_type").combobox('setValue', row.wide_type);

    if (row.wide_type==0)
    {
        $("#analysis_result").textbox('disable');
        $("#exp_proce_results").textbox('disable');
    }
    else if (row.wide_type==1)
    {
        $("#analysis_result").textbox('enable');
        $("#exp_proce_results").textbox('enable');
    }
    //setVal自定义函数 位置common.js 因为用了easyui-textbox 所以显示还需要特殊赋值
    setVal("#form_erp", row.erp);
    setVal("#form_subm_men", row.subm_men);
    setVal("#form_follow_up_people", row.follow_up_people);
    setVal("#pro_type", row.pro_type);
    setVal("#problem_description", row.problem_description);
    setVal("#analysis_result", row.analysis_result);
    setVal("#exp_proce_results", row.exp_proce_results);
    setVal("#temp_disposal", row.temp_disposal);
    setVal("#form_occurrence_time", row.occurrence_time);
}

function addDtl() {
    var eid = $("#dlg_event_id").val();
    console.info("addDtl:"+eid);

    if (eid == null) {
        U.msg('参数错误');
        return;
    }

    dialogDtl = $("#dlg_dtl").dialog({
        title: '添加处理细则',
        width: 450,
        height: 270,
        maximizable: false,
        modal: true,
        buttons: [{
            text: '确认',
            iconCls: 'icon-ok',
            handler: function () {
                var isValid = $("#form_dtl").form('validate');
                var addObj = [{"name":"eid","value":eid}];
                if (isValid) {
                    U.post({
                        url: getRootPath() + "/exception/addExceptionDtl",
                        loading: true,
                        data: getFormJson("#form_dtl", "", addObj),//$('#form_main').serialize(),
                        success: function (data) {
                            if (data.code == 200) {
                                U.msg('添加成功');
                                dialogDtl.dialog('close');
                                console.info("close:"+eid);
                                queryDetails();
                            } else if (data.code == 400) {
                                U.msg('参数验证失败');
                            }else if (data.code == 403) {
                                U.msg(data.message);
                            } else if (data.code == 409) {
                                U.msg('已存在');
                            } else {
                                U.msg('服务器异常');
                            }
                        }
                    });
                }
            }
        }, {
            text: '取消',
            handler: function () {
                dialogDtl.dialog('close');
            }
        }]
    });
    $("#form_dtl").form("clear");
    $.getJSON(getRootPath() + "/exception/list_dept", function (json) {
        $('#dept').combobox({
            data: json.data, //获取到的json 数据
            valueField: "id",
            textField: "dept_name"
        });
    });
}

function editDtl(id) {
    var row;
    if (id == null) {//点击datagrid上面的修改
        row = datagridDtl.datagrid('getSelected');
    } else {//点击datagrid对应行上的修改
        datagridDtl.datagrid('selectRow', id);
        row = datagridDtl.datagrid('getSelected');
    }

    if (row == null) {
        U.msg('请先选择一项处理细则');
        return;
    }

    dialogDtl = $("#dlg_dtl").dialog({
        title: '编辑处理细则',
        width: 450,
        height: 270,
        maximizable: false,
        modal: true,
        buttons: [{
            text: '确认',
            iconCls: 'icon-ok',
            handler: function () {
                var isValid = $("#form_dtl").form('validate');
                var addObj = [{"name":"id","value":row.id}];
                if (isValid) {
                    U.post({
                        url: getRootPath() + "/exception/editExceptionDtl",
                        loading: true,
                        data: getFormJson("#form_dtl", "", addObj),
                        success: function (data) {
                            if (data.code == 200) {
                                U.msg('修改成功');
                                dialogDtl.dialog('close');
                                queryDetails();
                            }else if (data.code == 400) {//参数验证失败
                                U.msg('参数验证失败');
                            }else if (data.code == 403) {
                                U.msg(data.message);
                            }else if (data.code == 404) {
                                U.msg('未找到该分类');
                            } else if (data.code == 409) {
                                U.msg('该分类已存在');
                            } else {
                                U.msg('服务器异常');
                            }
                        }
                    });
                }
            }
        }, {
            text: '取消',
            handler: function () {
                dialogDtl.dialog('close');
            }
        }]
    });

    $.getJSON(getRootPath() + "/exception/list_dept", function (json) {
        $('#dept').combobox({
            data: json.data, //获取到的json 数据
            valueField: "id",
            textField: "dept_name"
        });
        console.log(row.dept);
        $("#dept").combobox('setValue', row.dept);
    });
    //setVal自定义函数 位置common.js 因为用了easyui-textbox 所以显示还需要特殊赋值
    setVal("#content", row.content);
}

function removeDtl(id) {
    if (id == null) {
        var row = datagridDtl.datagrid('getSelected');
        if (row == null) {
            U.msg('请先选择处理细则');
            return;
        } else {
            id = row.id;
        }
    }

    parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function (data) {
        if (data) {
            U.get({
                url: getRootPath() + '/exception/deleExceptionDtl?id=' + id,
                loading: true,
                success: function (data) {
                    if (data.code == 200) {
                        U.msg('删除成功');
                        queryDetails();
                    } else if (data.code == 400) {//参数验证失败
                        U.msg('参数验证失败');
                    } else if (data.code == 403) {
                        U.msg(data.message);
                    }
                    else {
                        U.msg('服务器异常');
                    }
                }
            });
        }
    });
}

function FigureOut() {
    var eid = $("#dlg_event_id").val();

    if (eid == null) {
        U.msg('参数异常');
        return;
    }

    parent.$.messager.confirm('提示', '确认将此异常事件标记为已处理完毕？（注：已处理完成的异常事件不允许被任何形式的更改）', function (data) {
        if (data) {
            U.get({
                url: getRootPath() + '/exception/setEventStatusToFinish?eid=' + eid,
                loading: true,
                success: function (data) {
                    if (data.code == 200) {
                        U.msg('标记成功');
                        queryDetails();
                        queryRecord();
                    } else if (data.code == 400) {//参数验证失败
                        U.msg(data.message);
                    } else if (data.code == 403) {
                        U.msg('非法访问');
                    }
                    else {
                        U.msg('服务器异常');
                    }
                }
            });
        }
    });
}

function event_preview(row) {
    dialogEventPreview = $("#dlg_event_preview").dialog({
        title: '预览异常事件',
        width: 820,
        height: 480,
        maximizable: false,
        modal: true,
        buttons: [{
            text: '关闭',
            handler: function () {
                dialogEventPreview.dialog('close');
            }
        }]
    });

    console.info(row.problem_description);
    $("#preview_wide_type").text(row.wide_type==0?"订单资料异常":"机型履历异常");
    $("#preview_occurrence_time").text(row.occurrence_time==null?"":row.occurrence_time);
    $("#preview_erp").text(row.erp==null?"":row.erp);
    $("#preview_subm_men").text(row.subm_men==null?"":row.subm_men);
    $("#preview_dept").text(row.dept_name==null?"":row.dept_name);
    $("#preview_follow_up_people").text(row.follow_up_people==null?"":row.follow_up_people);
    $("#preview_pro_type").text(row.pro_type==null?"":row.pro_type);
    $("#preview_exception_type_name").text(row.exception_type_name==null?"":row.exception_type_name);
    $("#preview_problem_description").html(row.problem_description==null?"":row.problem_description.toString().replace('\n','<br/>').replace('\r\n','<br/>'));
    $("#preview_analysis_result").html(row.analysis_result==null?"":row.analysis_result.toString().replace('\n','<br/>').replace('\r\n','<br/>'));
    $("#preview_exp_proce_results").html(row.exp_proce_results==null?"":row.exp_proce_results.toString().replace('\n','<br/>').replace('\r\n','<br/>'));
    $("#preview_temp_disposal").html(row.temp_disposal==null?"":row.temp_disposal.toString().replace('\n','<br/>').replace('\r\n','<br/>'));
}

function open_chart_dlg() {

    dialogChart = $("#dlg_chart").dialog({
        title: '可视化图表',
        width: 920,
        height: 510,
        maximizable: false,
        modal: true,
        buttons: [{
            text: '关闭',
            handler: function () {
                dialogChart.dialog('close');
            }
        }]
    });

     chartDom = document.getElementById('chartMain');
     myChart = echarts.init(chartDom);

    addObj=[];
    U.post({
        url: getRootPath() + "/exception/getEtsd",
        loading: true,
        data: getFormJson("#chart_form", "", addObj),
        success: function (data) {
            if (data.code == 200) {
                var option = {
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b}: {c} ({d}%)'
                    },
                    legend: {
                        data: data.data.legend
                    },
                    series: [
                        {
                            name: '广泛类单元',
                            type: 'pie',
                            selectedMode: 'single',
                            radius: [0, '30%'],
                            label: {
                                position: 'inner',
                                fontSize: 14
                            },
                            labelLine: {
                                show: false
                            },
                            data: data.data.wideTypevalueData
                        },
                        {
                            name: '异常种类单元',
                            type: 'pie',
                            radius: ['45%', '60%'],
                            labelLine: {
                                length: 30
                            },
                            label: {
                                formatter: '{a|{a}}{abg|}\n{hr|}\n  {b|{b}：}{c}  {per|{d}%}  ',
                                backgroundColor: '#F6F8FC',
                                borderColor: '#8C8D8E',
                                borderWidth: 1,
                                borderRadius: 4,
                                rich: {
                                    a: {
                                        color: '#6E7079',
                                        lineHeight: 22,
                                        align: 'center'
                                    },
                                    hr: {
                                        borderColor: '#8C8D8E',
                                        width: '100%',
                                        borderWidth: 1,
                                        height: 0
                                    },
                                    b: {
                                        color: '#4C5058',
                                        fontSize: 14,
                                        fontWeight: 'bold',
                                        lineHeight: 33
                                    },
                                    per: {
                                        color: '#fff',
                                        backgroundColor: '#4C5058',
                                        padding: [3, 4],
                                        borderRadius: 4
                                    }
                                }
                            },
                            data: data.data.valueData
                        }
                    ]
                };
                option && myChart.setOption(option);
            }
        }
    });
}

function refChart(type) {
    addObj=[];
    switch (type) {
        case 0:
            U.post({
                url: getRootPath() + "/exception/getEtsd",
                loading: true,
                data: getFormJson("#chart_form", "", addObj),
                success: function (data) {
                    if (data.code == 200) {
                        var option = {
                            tooltip: {
                                trigger: 'item',
                                formatter: '{a} <br/>{b}: {c} ({d}%)'
                            },
                            legend: {
                                data: data.data.legend
                            },
                            series: [
                                {
                                    name: '广泛类单元',
                                    type: 'pie',
                                    selectedMode: 'single',
                                    radius: [0, '30%'],
                                    label: {
                                        position: 'inner',
                                        fontSize: 14
                                    },
                                    labelLine: {
                                        show: false
                                    },
                                    data: data.data.wideTypevalueData
                                },
                                {
                                    name: '异常种类单元',
                                    type: 'pie',
                                    radius: ['45%', '60%'],
                                    labelLine: {
                                        length: 30
                                    },
                                    label: {
                                        formatter: '{a|{a}}{abg|}\n{hr|}\n  {b|{b}：}{c}  {per|{d}%}  ',
                                        backgroundColor: '#F6F8FC',
                                        borderColor: '#8C8D8E',
                                        borderWidth: 1,
                                        borderRadius: 4,
                                        rich: {
                                            a: {
                                                color: '#6E7079',
                                                lineHeight: 22,
                                                align: 'center'
                                            },
                                            hr: {
                                                borderColor: '#8C8D8E',
                                                width: '100%',
                                                borderWidth: 1,
                                                height: 0
                                            },
                                            b: {
                                                color: '#4C5058',
                                                fontSize: 14,
                                                fontWeight: 'bold',
                                                lineHeight: 33
                                            },
                                            per: {
                                                color: '#fff',
                                                backgroundColor: '#4C5058',
                                                padding: [3, 4],
                                                borderRadius: 4
                                            }
                                        }
                                    },
                                    data: data.data.valueData
                                }
                            ]
                        };
                        myChart.clear();
                        option && myChart.setOption(option);
                    }
                }
            });
            break;
        case 1:
            U.post({
                url: getRootPath() + "/exception/getEtsd",
                loading: true,
                data: getFormJson("#chart_form", "", addObj),
                success: function (data) {
                    if (data.code == 200) {
                        var option = {
                            tooltip: {
                                trigger: 'axis',
                                axisPointer: {
                                    type: 'shadow'
                                }
                            },
                            grid: {
                                left: '3%',
                                right: '4%',
                                bottom: '3%',
                                containLabel: true
                            },
                            xAxis: [
                                {
                                    type: 'category',
                                    data: data.data.legend,
                                    axisTick: {
                                        alignWithLabel: true
                                    }
                                }
                            ],
                            yAxis: [
                                {
                                    type: 'value'
                                }
                            ],
                            series: [
                                {
                                    name: '数量',
                                    type: 'bar',
                                    barWidth: '60%',
                                    data: data.data.ints
                                }
                            ]
                        };
                        myChart.clear();
                        option && myChart.setOption(option);
                    }
                }
            });
            break;
        case 2:
            U.post({
                url: getRootPath() + "/exception/getDsd",
                loading: true,
                data: getFormJson("#chart_form", "", addObj),
                success: function (data) {
                    if (data.code == 200) {
                        var option = option = {
                            title: {
                                text: '责任部门归总可视化图表',
                                subtext: '统计饼图',
                                left: 'center'
                            },
                            tooltip: {
                                trigger: 'item'
                            },
                            legend: {
                                orient: 'vertical',
                                left: 'left'
                            },
                            series: [
                                {
                                    name: '责任部门分类',
                                    type: 'pie',
                                    radius: '50%',
                                    data: data.data.valueData,
                                    emphasis: {
                                        itemStyle: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    }
                                }
                            ]
                        };
                        myChart.clear();
                        option && myChart.setOption(option);
                    }
                }
            });
            break;

    }

}

function exportexcel() {
    window.location.href=getRootPath() +'/exception/exportExceptionEventData?erp='+$("#erp").val()+'&machineType='+$("#machineType").val()+
    '&conDept='+$("#conDept").val()+'&cusSentToName='+$("#cusSentToName").val()+'&conBillNo='+$("#conBillNo").val()+
    '&dept_id='+$("#dept_id").combobox('getValue')+'&exception_type_id='+$("#exception_type_id2").combobox('getValue')+
        '&subm_men='+$("#subm_men").val()+'&follow_up_people='+$("#follow_up_people").val()+'&wide_type='+$("#wide_type").combobox('getValue')+
        '&state='+$("#state").combobox('getValue')+'&occurrence_time_start='+$("#occurrence_time_start").val()+'&occurrence_time_end='+$("#occurrence_time_end").val()+
        '&submit_time_start='+$("#submit_time_start").val()+'&submit_time_end='+$("#submit_time_end").val();
}